package com.travel.mapper.content;

import com.travel.model.entity.content.TravelGuide;
import org.apache.ibatis.annotations.*;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Repository;

import java.util.Optional;
//旅行指南mapper 查询旅行指南 插入旅行指南 
@Mapper
@Repository("travelGuideMapperMyBatis")
public interface TravelGuideMapper {
    
    @Select("SELECT * FROM travel_guides WHERE id = #{id}")
    @Results({
        @Result(property = "user", column = "user_id", 
            one = @One(select = "com.travel.mapper.user.UserMapper.findById"))
    })
    Optional<TravelGuide> findById(@Param("id") Long id);
    
    @Insert("INSERT INTO travel_guides (title, content, user_id, city, status, created_time) " +
           "VALUES (#{title}, #{content}, #{user.id}, #{city}, #{status}, #{createdTime})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    void save(TravelGuide guide);
    
    @Select("SELECT * FROM travel_guides WHERE user_id = #{userId}")
    Page<TravelGuide> findByUser_Id(@Param("userId") Long userId, Pageable pageable);
    
    @Select("SELECT * FROM travel_guides WHERE city = #{city}")
    Page<TravelGuide> findByCity(@Param("city") String city, Pageable pageable);
    
    @Select("SELECT * FROM travel_guides WHERE city = #{city} AND status = #{status}")
    Page<TravelGuide> findByCityAndStatus(@Param("city") String city, @Param("status") Integer status, Pageable pageable);
} 